
package com.insigma.business.qrcode.common.converter;


import com.insigma.business.qrcode.common.converter.AbstractConverter;
import com.insigma.business.qrcode.welfare.dto.ScanCodeRecordBSearcher;
import com.insigma.business.qrcode.welfare.dto.ScanCodeRecordDTO;
import com.insigma.business.qrcode.welfare.entity.ScanCodeRecordDO;
import com.insigma.business.qrcode.welfare.request.ScanCodeRecordInsertRequest;
import com.insigma.business.qrcode.welfare.request.ScanCodeRecordSearchRequest;
import com.insigma.business.qrcode.welfare.request.ScanCodeRecordUpdateRequest;
import org.springframework.beans.BeanUtils;

import java.util.List;


public class ScanCodeRecordProviderConverter extends AbstractConverter<ScanCodeRecordDTO, ScanCodeRecordDO> {

    private final static ScanCodeRecordProviderConverter scanCodeRecordConverter = new ScanCodeRecordProviderConverter();

    private ScanCodeRecordProviderConverter(){}

    
    public static ScanCodeRecordBSearcher convertRequestSO2Searcher(final ScanCodeRecordSearchRequest request){
        final ScanCodeRecordBSearcher scanCodeRecordBSearcher = new ScanCodeRecordBSearcher(request.getPageNo(),
        request.getPageSize(),request.getSortKeyValueJoint());
        BeanUtils.copyProperties(request,scanCodeRecordBSearcher);
        return scanCodeRecordBSearcher;
    }

    
    public static ScanCodeRecordDO convertRequestUO2DO(final ScanCodeRecordUpdateRequest scanCodeRecordUpdateRequest) {
        final ScanCodeRecordDO scanCodeRecordDO = new ScanCodeRecordDO();
        BeanUtils.copyProperties(scanCodeRecordUpdateRequest,scanCodeRecordDO);
        
        return scanCodeRecordDO;
    }

    
    public static ScanCodeRecordDO convertRequestIO2DO(final ScanCodeRecordInsertRequest scanCodeRecordInsertRequest) {
        final ScanCodeRecordDO scanCodeRecordDO = new ScanCodeRecordDO();
        BeanUtils.copyProperties(scanCodeRecordInsertRequest,scanCodeRecordDO);
        return scanCodeRecordDO;
    }

    
    public static List<ScanCodeRecordDTO> convertResponseDOList2DTOList(final List<ScanCodeRecordDO> scanCodeRecordDOList){
        return scanCodeRecordConverter.convertGenericResponseDOList2DTOList(scanCodeRecordDOList);
    }

    
    public static ScanCodeRecordDTO convertResponseDO2DTO(final ScanCodeRecordDO scanCodeRecordDO){
        return scanCodeRecordConverter.convertGenericResponseDO2DTO(scanCodeRecordDO);
    }

    
    @Override
    protected ScanCodeRecordDTO doConvertResponseDO2DTO(ScanCodeRecordDO scanCodeRecordDO) {
        final ScanCodeRecordDTO scanCodeRecordDTO = new ScanCodeRecordDTO();
        try {
            BeanUtils.copyProperties(scanCodeRecordDO, scanCodeRecordDTO);
        }catch(RuntimeException be){
            
            return null;
        }
        return scanCodeRecordDTO;
    }

}
